package io.gitee.zhangbinhub.admin.controller.inner

import io.gitee.zhangbinhub.acp.boot.exceptions.WebException
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.admin.api.CommonPath
import io.gitee.zhangbinhub.admin.api.ServerApi
import io.gitee.zhangbinhub.admin.base.BaseController
import io.gitee.zhangbinhub.admin.entity.Application
import io.gitee.zhangbinhub.admin.service.ApplicationService
import io.gitee.zhangbinhub.admin.tools.TokenTools
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.noear.solon.annotation.Controller
import org.noear.solon.annotation.Inject
import org.noear.solon.annotation.Mapping
import org.noear.solon.core.handle.MethodType
import org.noear.solon.core.util.MimeType
import org.noear.solon.validation.annotation.Valid

@Valid
@Controller
@Api("应用信息（内部接口）")
open class InnerApplicationController(
    @Inject logAdapter: LogAdapter,
    private val applicationService: ApplicationService
) : BaseController(logAdapter) {

    @ApiOperation("获取应用信息", notes = "根据token查询应用详细信息")
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.innerBasePath + ServerApi.appInfo,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    @Throws(WebException::class)
    fun appInfo(): Application =
        applicationService.getApp(TokenTools.getAccessTokenModel()?.clientId ?: "")
            ?: throw WebException("找不到应用信息")
}
